<?php

namespace app\admin\controller;

use app\admin\model\Member as MemberModel;
use think\facade\Cache;
use think\facade\Validate;

class Index extends Admin {
    public function index() {
        $this->setMeta('后台首页');
        return $this->fetch();
    }


    // 更新个人信息
    public function profile() {
        if ($this->request->isPost()) {
            // 表单数据
            $data = $this->request->post();
            // 验证
            $validate = Validate::make(['mobile' => 'require'], ['mobile.require' => '手机号码不能为空']);
            $result = $validate->check($data);
            if (true !== $result) {
                $this->error($result);
            }
            $id = session('user_auth.id');
            if ($data = MemberModel::modifyMobileForEmployee($data['mobile'], $id)) {

                $this->log($id, '更新个人信息成功');
                $this->success('更新个人信息成功', cookie('__forward__'));
            } else {
                $this->error('更新个人信息失败');
            }

        } else {
            $id = session('user_auth.id');
            $info = MemberModel::get($id);
            //$employee = \app\admin\model\Employee::where(array('member_id' => $info['id']))->find();
            //$info['mobile'] = $employee['mobile'];
            $this->assign('info', $info);
            $this->setMeta('个人信息');
            return $this->fetch('profile');
        }
    }

    public function clear() {
        if (Cache::clear()) {
            $this->success("清除缓存成功");
        } else {
            $this->error("清除缓存失败");
        }
    }


}
